#!/bin/bash

echo "Creating new game request"

function usage () {
    echo "Usage: ./$0 <user_id> <opponent_id> <url>"
}

if [[ $# -eq 0 ]]; then
    # using defaults
    #URL="http://dabbler.herokuapp.com/api/v1/games/"
    URL="http://localhost:5000/api/v1/games/"
    USER_ID=2
else
    echo "Nr parms: $#"
    if [[ ! $# -ge 2 ]]; then
        usage
        exit 0
    fi

    if [[ $# -eq 2 ]]; then
        OPPONENT_ID=$2
        USER_ID=$1
    fi

    if [[ $# -eq 3 ]]; then
        OPPONENT_ID=$2
        USER_ID=$1
        URL=$3
    fi
fi

echo "User: $USER_ID"
echo "URL: $URL"

CMD="curl -X POST --data 'opponent_id=$OPPONENT_ID&user_id=$USER_ID' $URL"
echo "$CMD"
eval $CMD
